//周期执行脚本
debugger
let acctags = ['CB3_DFP_LIT_Accu_ACCU', 'CB3_AER01_FIT_ACCU_IN_ACCU', 'CB3_AER03_FIT_ACCU_IN_ACCU'];
getHistoryReport(acctags)
async function getHistoryReport(acctags) {
    const realData = await getRealData(acctags);
    //console.log(realData)
    //JSON.parse(realData.datas[0].TagValues[0]).V
    let startTime;
    let endTime;
    var currTime = new Date();
    startTime = currTime.format('yyyy-MM-dd');
    startTime = startTime + ' 00:00:00';
    endTime = currTime.format('yyyy-MM-dd hh:mm:ss');
    startTime = startTime.replace(/\//g, "-");
    endTimeacc = endTime.replace(/\//g, "-");
    var CB3_JZ1, CB3_JZ2, CB3_CZ, CBCZ, ZZCZ, QDCZ, TYCZ;
    let options1 = {
        "type": 0,
        "startTime": startTime,
        "endTime": endTime,
        "timebucket": '1h',
        "tags": acctags,
        //"columns": ["max","min","last","avg"],   //max:datamax min:datamin avg:dataaverage
        "columns": [],
        //"isDesc": false
    };
    GetHistorytagForReport(options1, function(res1) {
        res1 = res1.Body.records
        // console.log(res1);
        debugger
        //SZKMAX1 = $System.CN1_IPS_FIT_01_TOTAL;
        // SZKMAX1 = parseFloat(parseFloat(SZKMAX1).toFixed(2));
        //CB3_JZ = parseFloat($System.CB2_IPS_FIT_IW_4) - parseFloat(parseFloat(res1[acctags[0]][0]['data_first']).toFixed(2));
        CB3_CZ = parseFloat($System.CB3_DFP_LIT_Accu_ACCU) - parseFloat(parseFloat(res1[acctags[0]][0]['data_first']).toFixed(2));
        CB3_JZ1 = $System.CB3_AER01_FIT_ACCU_IN_ACCU - parseFloat(parseFloat(res1[acctags[1]][0]['data_first']).toFixed(2));
        CB3_JZ2 = $System.CB3_AER03_FIT_ACCU_IN_ACCU - parseFloat(parseFloat(res1[acctags[2]][0]['data_first']).toFixed(2));
        //QDCZ = $System.QD1_OMR_FIT01_V_ACC - parseFloat(parseFloat(res1[acctags[4]][0]['data_first']).toFixed(2));
        //TYCZ = $System.TY1_OMR_FIT01_V_ACC - parseFloat(parseFloat(res1[acctags[5]][0]['data_first']).toFixed(2));
        //$System.CB3_INFLOW_DTOTAL=CB3_JZ;
        $System.CB3_OUTFLOW_DTOTAL = CB3_CZ;
        $System.CB3_INFLOW_DTOTAL = CB3_JZ1 + CB3_JZ2;
        //$System.ZZ1_IPS_FIT_01_DTOTAL=ZZCZ;
        //$System.QD1_IPS_FIT_01_DTOTAL=QDCZ;
        //$System.TY1_IPS_FIT_01_DTOTAL=TYCZ;
    })
}

function getRealData(tagArr) {
    return new Promise((resolve, reject) => {
        GetRealtimeDatas({
             tagNames: tagArr
         }, resolve);
    });
}